var gJSdatePeriod = -7; // Set default Date duration for condition
var gJSdatePeriodMiddle = gJSdatePeriod; // Set other statsState Date duration for condition
var gJSdatePeriodLong = -124; // Set trLogService Date duration for condition
var gJSdateDuration = -1; //*364; // Set Date duration for byPass 

var gWidth = 0, gHeight = 0;
function resetSizeVal() {
	if (typeof (window.innerWidth) == 'number') { //Chrome
	     gWidth = window.innerWidth;
	     gHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	     gWidth = document.documentElement.clientWidth;
	     gHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE9
	     gWidth = document.body.clientWidth;
	     gHeight = document.body.clientHeight;
	}
}
resetSizeVal();
function getInitialWidth(){
    xWidth = null;
    if (gWidth > 0){
        xWidth = gWidth;
    }
    
    return xWidth;
}
function getWidth(){
	return getInitialWidth();
}
function getInitialHeight(){
    xHeight = null;
    if (gHeight > 0){
        xHeight = gHeight;
    }
    
    return xHeight;
}
function getHeight(){
	return getInitialHeight();
}
function getGlobalWidth(){
    xWidth = null;
    resetSizeVal();
    if (gWidth > 0){
        xWidth = gWidth;
    }
    
    return xWidth;
}

function getGlobalHeight(){
    xHeight = null;
    resetSizeVal();
    if (gHeight > 0){
        xHeight = gHeight;
    }
    
    return xHeight;
}

function isUndefined(pObject) {
	if (pObject == "" || pObject == "undefined" || pObject == "null" || pObject == null) return true;
	return false;
}
function isDefined(pObject) {
	return !isUndefined(pObject);
}

function ctHeight() {
	$('.box_s:first-child').addClass('first');
	var ctlEl = document.getElementById("conLeft");
	var ctrEl = document.getElementById("conRight");
	ctlEl.style.height = ctrEl.offsetHeight - 36 + "px";

	var bgrEl = document.getElementById("bg_right");
	var topEl = document.getElementById("top");
	var h3El = document.getElementById("h");
	bgrEl.style.height = topEl.offsetHeight + h3El.offsetHeight + "px";
}

function movePage(startRow) {
	document.getElementById("_startRowNo").value = startRow;
	
	pmModule.loadList();
}

function refresh() {
	document.location.reload();
}

function retrieveAlarms() {
	var url;

	url = 'retrieveAlarmHist.action';

	$.getJSON(url, function(data) {

		// 알람리스트 초기화
		$('#tabContent1 > tbody').contents().remove();
		$('#tabContent2 > tbody').contents().remove();
		// 리소스 경보.
		var resAlarmRow = "";

		$.each(data.resAlarm, function(key, value) {
			resAlarmRow = "<tr><td>";
			if (value.alarmlevel == "3") {
				resAlarmRow += "<span class='state critical'>3</span>";
			} else if (value.alarmlevel == "2") {
				resAlarmRow += "<span class='state major'>2</span>";
			} else if (value.alarmlevel == "1") {
				resAlarmRow += "<span class='state minor'>1</span>";
			} else {
				resAlarmRow += "<span class='state normal'>0</span>";
			}
			resAlarmRow += "</td>";
			resAlarmRow += "<td>" + value.resourcetypename + "</td>";
			resAlarmRow += "<td>" + value.systemname + "</td>";
			// resAlarmRow+="<td>"+value.utilization+"</td>";
			// resAlarmRow+="<td>N/A</td>";
			resAlarmRow += "<td class='msg'>" + value.message + "</td>";
			resAlarmRow += "<td>" + (value.eventdate).substr(0, 10)
					+ "&nbsp;&nbsp;" + (value.eventdate).substr(11, 8)
					+ "</td>";
			resAlarmRow += "<tr/>";
			$('#tabContent1 > tbody').append(resAlarmRow);
		});

		// 서비스 경보.
		var svcAlarmRow = "";

		$.each(data.svcAlarm, function(key, value) {
			svcAlarmRow = "<tr><td>";
			if (value.alarmdesc == "Critical") {
				svcAlarmRow += "<span class='state critical'>3</span>";
			} else if (value.alarmdesc == "Major") {
				svcAlarmRow += "<span class='state major'>2</span>";
			} else if (value.alarmdesc == "Minor") {
				svcAlarmRow += "<span class='state minor'>1</span>";
			} else {
				svcAlarmRow += "<span class='state normal'>0</span>";
			}
			svcAlarmRow += "</td>";
			svcAlarmRow += "<td>" + value.alarmtypename + "</td>";
			svcAlarmRow += "<td>" + value.systemname + "</td>";
			svcAlarmRow += "<td class='msg'>" + value.message + "</td>";
			svcAlarmRow += "<td>" + (value.alarmdate).substr(0, 10)
					+ "&nbsp;&nbsp;" + (value.alarmdate).substr(11, 8)
					+ "</td>";
			// svcAlarmRow+="<td>"+(value.alarmdate).substr(11,8)+"</td>";
			svcAlarmRow += "<tr/>";
			$('#tabContent2 > tbody').append(svcAlarmRow);
		});

		$('#tabContent1 > tbody > tr:nth-child(even)').remove();
		$('#tabContent1 > tbody > tr:nth-child(even)').addClass('even');
		$('#tabContent2 > tbody > tr:nth-child(even)').remove();
		$('#tabContent2 > tbody > tr:nth-child(even)').addClass('even');

		//var sndAlarmRow = "";

		$.each(data.sndAlarm, function(key, value) {

			$.fn.soundPlay({
				url : '/sounds/' + value + '.mp3',
				playerId : 'embed_player',
				command : 'play'
			});

		});

	});

	setTimeout(retrieveAlarms, 10000); // 다시 10초 후 호출(반복)
}

// vm수정
function vmModAct() {
	var frm = document.dForm;
	var servideId = $(".ipt_cr:checked").val();
	frm.action = "vmResource.action";

	if (servideId == undefined) {
		alert("수정할 VM을 선택하세요.");
		return;
	}

	$("#serviceId").val(servideId);
	frm.submit();
}

// vm삭제
function vmDelActDt(url) {
	if (!confirm("VM을 삭제 하시겠습니까?")) {
		return;
	}

	location.href = url;

}

// vm삭제
function vmDelAct() {
	var frm = document.dForm;
	var servideId = $(".ipt_cr:checked").val();
	frm.action = "vmDeleteExe.action";

	if (!confirm("VM을 삭제 하시겠습니까?")) {
		return;
	}

	if (servideId == undefined) {
		alert("삭제할 VM을 선택하세요.");
		return;
	}

	$("#serviceId").val(servideId);
	frm.submit();

}

function vmControlAct(serviceId) {
	var frm = document.dForm;
	var servideId = $(".ipt_cr:checked").val();

	if (servideId == undefined) {
		alert("변경할 VM을 선택하세요.");
		return;
	}

	var controlType = document.getElementById("controlType");

	if (controlType.value == "") {
		alert("변경할 상태를 선택하세요.");
		return;
	}
	frm.action = "vmControlExe.action";

	$("#serviceId").val(servideId);

	frm.submit();

}

// vm수정
function vmCreateConfirmAct() {
	var frm = document.dForm;

	var templateName = $(".ipt_cr:checked").val();

	if (templateName == undefined) {
		alert("생성할 템플릿을 선택하세요.");
		return false;
	}

	var obj = new Object();

	var r = showModalDialog("vmCreationConfirm.action?serverPool="
			+ $("#serverPool").val() + "&templateName=" + templateName, obj,
			'dialogHeight=320px; dialogWidth=400px; help=no; center=yes');

	if (r.confirm) {

		$('#net_mask').val(r.net_mask);
		$('#dns').val(r.dns);
		$('#gateway').val(r.gateway);
		$('#bridge').val(r.bridge);
		$('#root_id').val(r.root_id);
		$('#root_pw').val(r.root_pw);
		$('#host_name').val(r.host_name);
		$('#host_ip').val(r.host_ip);
		$('#cpu_cap').val(r.cpu_cap);
		$('#mem_cap').val(r.mem_cap);
		$('#serviceType').val(r.serviceType);

		frm.action = "vmCreationExe.action";
		frm.submit();
	}

	return false;
}

function vmLiveMigration(serviceId) {
	var frm = document.dForm;
	var servideId = $(".ipt_cr:checked").val();

	if (servideId == undefined) {
		alert("라이브마이그레이션 대상 VM을 선택하세요.");
		return;
	}

	frm.action = "vmLiveMigration.action";

	$("#serviceId").val(servideId);

	frm.submit();

}

function vmSave(serviceId) {
	var frm = document.dForm;
	var servideId = $(".ipt_cr:checked").val();

	if (servideId == undefined) {
		alert("템플릿으로 저장할 VM을 선택하세요.");
		return;
	}

	frm.action = "vmSave.action";

	$("#serviceId").val(servideId);

	frm.submit();

}

function powerOn_Ajax(serviceId) {
	location.href = 'vmControl.action?serviceId=' + serviceId
			+ '&control=powerOn';
}
// 파워OFF
function powerOff_Ajax(serviceId) {

	location.href = 'vmControl.action?serviceId=' + serviceId
			+ '&control=powerOff';

	/*
	 * if(!confirm("PowerOFF 하시겠습니까?")){ return; }
	 * 
	 * var param = "serviceId="+serviceId;
	 * 
	 * $.ajax({ url: "powerOffExe.action", type: "POST", data: param, dataType:
	 * "text", timeout: 10000, error: function(){ alert("오류가 발생했습니다. 잠시 후 다시 시도해
	 * 주세요."); }, success: function(data){ var rtn = eval('('+data+')');
	 * if(rtn.resultStr=="success"){ //상태이미지 변경(power Off)
	 * $("#vmStateImg").attr("src","/images/b_running.gif"); }else{
	 * alert("powerOff에 실패하였습니다."); } return; } });
	 */

}

// serverPool 조회
function poolSearch() {

	var frm = document.pForm;
	frm.action = "poolList.action";
	frm.submit();
}

// serverPool수정
function poolModAct() {

	var frm = document.pForm;
	var nodeGroupId = $(".ipt_cr:checked").val();
	frm.action = "poolReg.action";

	if (nodeGroupId == undefined) {
		alert("수정할 서버 풀을 선택하세요.");
		return;
	}

	$("#nodeGroupId").val(nodeGroupId);
	$("#mode").val("update");
	frm.submit();
}

// server수정
function serverModAct() {

	var frm = document.pForm;
	var nodeId = $(".ipt_cr:checked").val();
	frm.action = "serverReg.action";

	if (nodeId == undefined) {
		alert("수정할 서버를 선택하세요.");
		return;
	}

	$("#nodeId").val(nodeId);
	$("#mode").val("update");
	frm.submit();
}

// vmList 조회
function vmSearch() {

	var frm = document.dForm;
	frm.action = "vmList.action";
	frm.submit();
}

// main 조회
function mainSearch() {

	var frm = document.dForm;
	frm.action = "mainState.action";
	frm.submit();
}

$(document)
		.ready(
				function() {
					// table 짝수열 배경색변경
					$('.tbl > tbody > tr:nth-child(even)').addClass('even');

					// sorting table
					var reSortColors = function($table) {
						$('tbody tr:odd', $table).removeClass('even').addClass(
								'odd');
						$('tbody tr:even', $table).removeClass('odd').addClass(
								'even');
					};
					$('table.sortable')
							.each(
									function() {
										var $table = $(this);
										reSortColors($table);

										$('th', $table)
												.each(
														function(column) {
															var $header = $(this);
															if ($header
																	.is('.sorting')) {
																$header
																		.addClass(
																				'clickable')
																		.hover(
																				function() {
																					$header
																							.addClass('hover');
																				},
																				function() {
																					$header
																							.removeClass('hover');
																				})
																		.click(
																				function() {

																					var sortDirection = 1;
																					if ($header
																							.is('.sorted-asc')) {
																						sortDirection = -1;
																					}
																					// 변수
																					// 삽입

																					var rows = $table
																							.find(
																									'tbody > tr')
																							.get();
																					rows
																							.sort(function(
																									a,
																									b) {
																								if ($header
																										.is('.int')) {
																									var keyA = parseInt(
																											$
																													.trim($(
																															a)
																															.children(
																																	'td')
																															.eq(
																																	column)
																															.text()),
																											10);
																									var keyB = parseInt(
																											$
																													.trim($(
																															b)
																															.children(
																																	'td')
																															.eq(
																																	column)
																															.text()),
																											10);
																									if ($header
																											.is('.sorted-asc')) {
																										return keyA
																												- keyB;
																									} else {
																										return keyB
																												- keyA;
																									}
																								} else if ($header
																										.is('.img')) {

																									var keyA = $(
																											a)
																											.children(
																													'td')
																											.eq(
																													column)
																											.find(
																													'img')
																											.attr(
																													'src')
																											.toUpperCase();
																									var keyB = $(
																											b)
																											.children(
																													'td')
																											.eq(
																													column)
																											.find(
																													'img')
																											.attr(
																													'src')
																											.toUpperCase();
																									if (keyA < keyB)
																										return -sortDirection;
																									if (keyA > keyB)
																										return sortDirection;
																								} else {
																									var keyA = $(
																											a)
																											.children(
																													'td')
																											.eq(
																													column)
																											.text()
																											.toUpperCase();
																									var keyB = $(
																											b)
																											.children(
																													'td')
																											.eq(
																													column)
																											.text()
																											.toUpperCase();
																									if (keyA < keyB)
																										return -sortDirection;
																									if (keyA > keyB)
																										return sortDirection;
																								}

																								return 0;
																							});
																					$
																							.each(
																									rows,
																									function(
																											index,
																											row) {
																										$table
																												.children(
																														'tbody')
																												.append(
																														row);
																									});

																					$table
																							.find(
																									'th')
																							.removeClass(
																									'sorted-asc')
																							.removeClass(
																									'sorted-desc');
																					if (sortDirection == 1) {
																						$header
																								.addClass('sorted-asc');
																					} else {
																						$header
																								.addClass('sorted-desc');
																					}

																					reSortColors($table);
																				});
															}
														});
									});

				});

function selectCombo(id, value) {

	target = document.getElementById(id);

	for ( var i = 0; i < target.options.length; i++) {
		if (target.options[i].value == value) {
			target.options[i].selected = true;
			break;
		}
	}
}

// 사용자등록
function regUser() {

	if (confirm("신규사용자 승인요청 하시겠습니까?")) {

		var frm = document.uForm;
		frm.action = "userRegExe.action";
		var reqServices = "";

		$("input:checkbox:checked").each(function(column) {
			reqServices += $(this).val() + "|";
		});

		var reqAuth = $(".ipt_radio:checked").val();

		$("#reqServices").val(reqServices);
		$("#reqAuth").val(reqAuth);

		frm.submit();
	}
}

// 신규사용자승인
function newUserReg() {

	if ($("input:checkbox:checked").length < 1) {
		alert("먼저 사용자를 선택해주세요.");
		return;
	}

	if (confirm("신규사용자요청 승인을 하시겠습니까?")) {

		var frm = document.uForm;
		frm.action = "newUserMngExe.action";

		frm.submit();

	}

}

// 사용자권한 승인
function userAuthReg() {

	if ($("input:checkbox:checked").length < 1) {
		alert("먼저 사용자를 선택해주세요.");
		return;
	}

	if (confirm("사용자권한요청 승인을 하시겠습니까?")) {

		var frm = document.uForm;
		frm.action = "userAuthMngExe.action";

		frm.submit();

	}
}

// 사용자삭제
function deleteUser() {

	if ($("input:checkbox:checked").length < 1) {
		alert("먼저 사용자를 선택해주세요.");
		return;
	}

	if (confirm("사용자삭제를 하시겠습니까?")) {
		var frm = document.uForm;
		frm.action = "userDeleteExe.action";

		frm.submit();
	}
}

// chkbox 전체선택
function chkAll() {

	if ($("#chkbox").is(':checked')) {
		$("input:checkbox").attr("checked", "");
	} else {
		$("input:checkbox").attr("checked", false);
	}

}

function getNowDate(n) {
	var now = new Date();
	var nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + "." + now.getMilliseconds();
	if (n == "yyyymmddhhmmssmi") {
		nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + "." + now.getMilliseconds();
	} else if (n == "yyyymmddhhmmss") {
		nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
	} else if (n == "yyyymmddhhmm") {
		nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes();
	} else if (n == "yyyymmddhh") {
		nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate() + " " + now.getHours();
	} else if (n == "yyyymmdd") {
		nowTime = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate();
	}
	
	return nowTime;
}

function convertDateFormat(date, format) {
	var getDate = new Date(date);
	
	return getDate.format(format);
}

/**
 * 날짜 계산  (ASP의 DATEADD와 같은 방식)
 * @param string pInterval 계산 방식 월:"m" 일:"d"
 * @param string pAddVal 날짜 텀
 * @param string pYyyymmdd 기준일
 * @param string pDelimiter 표기형식 "-" , "/"
 */
function addDate(pInterval, pAddVal, pYyyymmdd, pDelimiter)
{
	var yyyy;
	var mm;
	var dd;
	var cDate;
	var cYear, cMonth, cDay;

	if (pDelimiter != "") {
		pYyyymmdd = pYyyymmdd.replace(eval("/\\" + pDelimiter + "/g"), "");
	}
	yyyy = pYyyymmdd.substr(0, 4);
	mm  = pYyyymmdd.substr(4, 2);
	dd  = pYyyymmdd.substr(6, 2);

	if (pInterval == "yyyy") {
		yyyy = (yyyy * 1) + (pAddVal * 1);
	} else if (pInterval == "m") {
		mm  = (mm * 1) + (pAddVal * 1);
	} else if (pInterval == "d") {
		dd  = (dd * 1) + (pAddVal * 1);
	}

	cDate = new Date(yyyy, mm - 1, dd); // 12월, 31일을 초과하는 입력값에 대해 자동으로 계산된 날짜가 만들어짐.
	cYear = cDate.getFullYear();
	cMonth = cDate.getMonth() + 1;
	cDay = cDate.getDate();
	cMonth = cMonth < 10 ? "0" + cMonth : cMonth;
	cDay = cDay < 10 ? "0" + cDay : cDay;

	if (pDelimiter != "") {
		return cYear + pDelimiter + cMonth + pDelimiter + cDay;
	} else {
		return cYear + cMonth + cDay;
	}
}

function isNumber(value) {
    var num = parseInt(value); // 정수 변환

    if (isNaN(num)) { // 값이 NaN 이면 숫자 아님.
        return false;
    }
    return true;
}

function getDateDiff(date1, date2) {
	var arrDate1 = date1.split("-");
	var getDate1 = new Date(parseInt(arrDate1[0]), parseInt(arrDate1[1]) - 1, parseInt(arrDate1[2]));
	var arrDate2 = date2.split("-");
	var getDate2 = new Date(parseInt(arrDate2[0]), parseInt(arrDate2[1]) - 1, parseInt(arrDate2[2]));
	var getDiffTime = getDate1.getTime() - getDate2.getTime();

	return Math.floor(getDiffTime / (1000 * 60 * 60 * 24));
}

function randomRange(n1, n2) {
	return Math.floor((Math.random() * (n2 - n1 + 1)) + n1 );
}

var colorCode = [
                 "#ff7e00",
                 "#ffea00",
                 "#30ff00",
                 "#004eff",
                 "#b400ff",
                 "#00fffc",
                 "#b4ff00",
                 "#ffb0f3",
                 "#4f805f",
                 "#9a8d78",
                 "#a37db6"
                 ];

function randomColor(n) {
	var colorNumber = Math.floor(Math.random() * n);
	
	return colorCode[colorNumber];
}

//*** 팝업레이어 관련 시작 ****//
//팝업레이어 호출
function frame_popup(s,c,w,h)
{
	NcloseLayer();	//레이어 버튼 클릭시 스페이스바를 누르면 창이 중복으로 뜨게되어 오류남 (정정민 : 2011.01.25)
	if (!w) w = 600;
	if (!h) h = 400;
	var pixelBorder = 0;
	var titleHeight = 16;
	w += pixelBorder * 2;
	h += pixelBorder * 2 + titleHeight;
	var bodySH = document.body.scrollHeight;
	var bodyW = $(window).width();
	var bodyH = $(window).height();
	var posX = (bodyW - w) / 2;
	var posY = (bodyH - h) / 2;

	var obj = document.createElement("div");
	with (obj.style){
		position = "absolute";
		zIndex = "999";
		left = '0px';
		top = '0px';
		width = "100%";
		height = (bodySH > bodyH ? bodySH : bodyH) + "px";
		background = "url(images/ui-bg_diagonals-thick_20_666666_40x40.png) Black 50% 50%";
		filter = "Alpha(Opacity=50)";
		opacity = "0.5";
	}
	obj.id = "objPopupLayerBg";
	document.body.appendChild(obj);
	$(window).resize(function(){
		var MbodySH = document.body.scrollHeight;
		var MbodyW = $(window).width();
		var MbodyH = $(window).height()-35;	 //사이즈 이동시 상하위치 35px보정함
		var MposX = (MbodyW - w) / 2;
		var MposY = (MbodyH - h) / 2;
		_ID('objPopupLayerBg').style.height = MbodySH + "px";
		_ID('objPopupLayer').style.left = (MposX + $(window).scrollLeft()) + "px";
		_ID('objPopupLayer').style.top = (MposY + $(window).scrollTop()) + "px";
	});

	var obj = document.createElement("div");
	with (obj.style){
		position = "absolute";
		zIndex = "999";
		left = (posX + $(window).scrollLeft()) + "px";
		top = (posY + $(window).scrollTop()) + "px";
		width = w + "px";
		height = (h + 29) + "px";
		backgroundColor = "#FFFFFF";
		border = "3px solid #DDDDDD";
	}
	obj.id = "objPopupLayer";

	document.body.appendChild(obj);
	var topsubject = document.createElement("div");
	var addHtml		= '';
	addHtml += "<div Class='blockMsg'>";
	addHtml += "	<div style='position:relative; padding:5px 0 0 5px; height:22px;' class='ui-widget-header'>";
	addHtml += "	<span>"+(c != undefined && c != '' ? c : '')+"</span>";
	addHtml += "	<span id='spanLayerPopupClose' style='position:absolute; top:7px; right:3px;' class='ui-icon ui-icon-closethick hand'><!--close--></span>";
	addHtml += "	</div>";
	addHtml += "</div>";
	topsubject.innerHTML =addHtml ;
	obj.appendChild(topsubject);
	$('div.blockMsg #spanLayerPopupClose').click(function() {NcloseLayer();});
	$('#objPopupLayerBg').click(function() {NcloseLayer();});
	var ifrm = document.createElement("iframe");
	with (ifrm.style){
		width = (w) + "px";
		height = (h - pixelBorder * 2 ) + "px";
	}
	ifrm.frameBorder = '0px';
	ifrm.src = s;
	obj.appendChild(ifrm);
}

//객체비움
function _ID(obj){return document.getElementById(obj);}

//닫기버튼 클릭시
function NcloseLayer(){
	$(window).unbind("resize");
	$('div.blockMsg #spanLayerPopupClose').unbind("click");
	$('#objPopupLayerBg').unbind("click");
	$('#blockMsg').remove();
	$('#objPopupLayer').remove();
	$('#objPopupLayerBg').remove();
}
//*** 팝업레이어 관련 끝 ****//

//*** 컨펌레이어 관련 시작 ****//
//컨펌레이어 호출
function frame_confirm(s,c,d,w,h)
{
	NcloseConfirmLayer();	//레이어 버튼 클릭시 스페이스바를 누르면 창이 중복으로 뜨게되어 오류남 (정정민 : 2011.01.25)
	if (!w) w = 600;
	if (!h) h = 400;
	var pixelBorder = 0;
	var titleHeight = 16;
	w += pixelBorder * 2;
	h += pixelBorder * 2 + titleHeight;
	var bodySH = document.body.scrollHeight;
	var bodyW = $(window).width();
	var bodyH = $(window).height();
	var posX = (bodyW - w) / 2;
	var posY = (bodyH - h) / 2;

	var obj = document.createElement("div");
	with (obj.style){
		position = "absolute";
		zIndex = "999";
		left = '0px';
		top = '0px';
		width = "100%";
		height = (bodySH > bodyH ? bodySH : bodyH) + "px";
		background = "url(/Image/ui-bg_diagonals-thick_20_666666_40x40.png) Black 50% 50%";
		filter = "Alpha(Opacity=50)";
		opacity = "0.5";
	}
	obj.id = "objConfirmLayerBg";
	document.body.appendChild(obj);
	$(window).resize(function(){
		var MbodySH = document.body.scrollHeight;
		var MbodyW = $(window).width();
		var MbodyH = $(window).height()-35;	 //사이즈 이동시 상하위치 35px보정함
		var MposX = (MbodyW - w) / 2;
		var MposY = (MbodyH - h) / 2;
		_getID('objConfirmLayerBg').style.height = MbodySH + "px";
		_getID('objConfirmLayer').style.left = (MposX + $(window).scrollLeft()) + "px";
		_getID('objConfirmLayer').style.top = (MposY + $(window).scrollTop()) + "px";
	});

	var obj = document.createElement("div");
	with (obj.style){
		position = "absolute";
		zIndex = "999";
		left = (posX + $(window).scrollLeft()) + "px";
		top = (posY + $(window).scrollTop()) + "px";
		width = w + "px";
		height = (h + 29) + "px";
		backgroundColor = "#FFFFFF";
		border = "3px solid #DDDDDD";
	}
	obj.id = "objConfirmLayer";

	document.body.appendChild(obj);
	var topsubject = document.createElement("div");
	var addHtml		= '';
	addHtml += "<div Class='blockMsg'>";
	addHtml += "	<div style='position:relative; padding:5px 0 0 5px; height:22px;' class='ui-widget-header'>";
	addHtml += "	<span>"+(c != undefined && c != '' ? c : '')+"</span>";
	addHtml += "	<span id='spanLayerConfirmClose' style='position:absolute; top:7px; right:3px;' class='ui-icon ui-icon-closethick hand'><!--close--></span>";
	addHtml += "	</div>";
	addHtml += "</div>";

	topsubject.innerHTML =addHtml ;
	obj.appendChild(topsubject);
	$('div.blockMsg #spanLayerConfirmClose').click(function() {NcloseConfirmLayer();});
	$('#objConfirmLayerBg').click(function() {NcloseConfirmLayer();});
	var ifrm = document.createElement("iframe");
	with (ifrm.style){
		width = (w) + "px";
		height = (h - pixelBorder * 2 ) + "px";
	}
	ifrm.frameBorder = '0px';
	ifrm.src = s + "?contents=" + (d != undefined && d != '' ? d : '');

//	var addHtmlContents		= '';
//	addHtmlContents += "<p id='confirm_msg'>";
//	addHtmlContents += "	<span>"+(d != undefined && d != '' ? d : '')+"</span>";
//	addHtmlContents += "</p>";
//	ifrm.innerHTML =addHtml ;
	
	obj.appendChild(ifrm);
}

//객체비움
function _getID(obj){return document.getElementById(obj);}

//닫기버튼 클릭시
function NcloseConfirmLayer(){
	$(window).unbind("resize");
	$('div.blockMsg #spanLayerConfirmClose').unbind("click");
	$('#objConfirmLayerBg').unbind("click");
	$('#blockMsg').remove();
	$('#objConfirmLayer').remove();
	$('#objConfirmLayerBg').remove();
}
//*** 컨펌레이어 관련 끝 ****//

function appendMessage(msg, pObjectName) {
	var pObject = $(pObjectName);
	if (isDefined(pObject)) {
		msg += " "+pObjectName+"";
		if (isDefined(pObject.css("height"))) {
			msg += " h="+pObject.css("height").replace("px","");
		}
		if (isDefined(pObject.css("width"))) {
			msg += " w="+pObject.css("width").replace("px","");
		}
	}
	return msg;
}

function getJsObjectValue(pObjectName) {
	//alert("===== pObjectName ["+pObjectName+"]");
	var objectValue = null;
	var pObject = $(pObjectName);
	//alert("===== pObject["+pObject+"]");
	if (isDefined(pObject)) {
		objectValue = pObject.val();
	}
	return objectValue;
}
//var gltw = parseInt($("#formlistarea1.list_table").css("width").replace("px",""))-10;   
function getObjectValue(pObjectName, pObjectAttr) {
	var objectValue = null;
	var pObject = $(pObjectName);
	if (isDefined(pObject)) {
		if (isDefined(pObject.css(pObjectAttr))) {
			objectValue = parseInt(pObject.css(pObjectAttr).replace("px",""));
		}
	}
	return objectValue;
}
//     $("#list_form7").css("height", gch - parseInt(ret+10));
function setObjectValue(pObjectName, pObjectAttr, pValue) {
	var resValue = false;
	var pObject = $(pObjectName);
	if (isDefined(pObject)) {
		pObject.css(pObjectAttr, pValue);
		resValue = true;
	}
	return resValue;
}

function sortTable() {
	$("table.sortable").each(function() {
		var $table = $(this);
		
		$('th', $table).each(function(column) {
			var $header = $(this);
			
			if ($header.is('.sorting')) {
				$header.addClass('clickable').hover(function() {
					$header.addClass('hover');
				}, function() {
					$header.removeClass('hover');
				}).click(function() {
					column = $(this).attr("id");
					
					var sortDirection = 1;
					
					if ($header.is('.sorted-asc')) {
						sortDirection = -1;
					}

					$table2 = $("table.sortData");
					var rows = $table2.find("tr").get();
					rows.sort(function(a, b) {
						if ($header.is('.int')){
							var keyA = parseInt($.trim($(a).children('td').eq(column).text()),10);
							var keyB = parseInt($.trim($(b).children('td').eq(column).text()),10);
							
							if ($header.is('.sorted-asc')) {
								return keyA - keyB;
							}else{
								return keyB - keyA;
							}
						}else if ($header.is('.img')){
							var keyA = $(a).children('td').eq(column).find('img').attr('src').toUpperCase();
							var keyB = $(b).children('td').eq(column).find('img').attr('src').toUpperCase();
						
							if (keyA < keyB) return -sortDirection;
							if (keyA > keyB) return sortDirection;
						}else{
							var keyA = $(a).children('td').eq(column).text().toUpperCase();
							var keyB = $(b).children('td').eq(column).text().toUpperCase();
				
							if (keyA < keyB) return -sortDirection;
							if (keyA > keyB) return sortDirection;
						}
						return 0;
					});
					$.each(rows, function(index, row) {
						$table2.children('tbody').append(row);
					});
					
					$table.find('th').removeClass('sorted-asc').removeClass('sorted-desc').removeClass('checkTitle');
					$table.find('img').attr("src", $table.find('img').attr("src").replace("arrow_up_check","arrow_up"));
					$table.find('img').attr("src", $table.find('img').attr("src").replace("arrow_down_check","arrow_up"));
					if (sortDirection == 1) {
						$header.addClass('sorted-asc').addClass('checkTitle');
						$header.find('img').attr("src", $header.find('img').attr("src").replace("arrow_up","arrow_up_check"));	
					} else {
						$header.addClass('sorted-desc').addClass('checkTitle');
						$header.find('img').attr("src", $header.find('img').attr("src").replace("arrow_up","arrow_down_check"));
					}
				});
			}
		});
	});  
}   

function checkUserAuth() {
	var retLevel = parent.$("#_menuAuth").val();
	
	if (parent.$("#_userLevel").val() > 7)
		retLevel = "2";

	return retLevel;
}